package com.jiunuan.live.core.server.common;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @Author: JiuNuan
 * @CreateTime: 2024-08-10 21:16
 * @Description: 编码器
 */

public class TcpImMsgEncoder extends MessageToByteEncoder {
    @Override
    protected void encode(ChannelHandlerContext ctx, Object msg, io.netty.buffer.ByteBuf out) throws Exception {
        ImMsg imMsg = (ImMsg) msg;
        out.writeShort(imMsg.getMagic());
        out.writeInt(imMsg.getCode());
        out.writeInt(imMsg.getLen());
        out.writeBytes(imMsg.getBody());
//        ctx.writeAndFlush(out);
    }
}
